﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

namespace Api.Shared.WebSocket
{
    [AllowAnonymous] // 添加此特性允许匿名访问
    public class MyHub : Hub
    {
        public Task SendMessage(string user, string message)
        {
            string connectionId = this.Context.ConnectionId;
            return Clients.All.SendAsync("broadcastMessage", user, message);
        }
        public override Task OnConnectedAsync()
        {
            // Logic when a new client connects
            return base.OnConnectedAsync();
        }
        public override Task OnDisconnectedAsync(Exception? exception)
        {
            // Logic when a client disconnects
            return base.OnDisconnectedAsync(exception);
        }

    }
}
